home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac: Not for Sale
/
Another.not.for.sale (Australia).iso
/
fade into you
/
getting there
/
Apps
/
AuthMan 1.0.8
/
AuthMan XCMD
/
xcmd.c
< prev
Wrap
C/C++ Source or Header
|
1993-11-19
|
5KB
|
196 lines
/*
* Copyright (c) 1992-1993 Regents of The University of Michigan.
* All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation, and that the name of The University
* of Michigan not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. This software is supplied as is without expressed or
* implied warranties of any kind.
*
* Campus Computing Sites, Sales, and Service
* The University of Michigan
* c/o Robert John Churchill
* 535 W. William Street
* Ann Arbor, Michigan
* +1-313-936-2528
* rjc@ccs.itd.umich.edu
*/
#include <Errors.h>
#include <HyperXCmd.h>
#include <Packages.h>
#include "authLibrary.h"
#define XCMD_VERSION 1
OSErr Xcmdversion(XCmdPtr paramPtr,short refNum,Str255);
OSErr Xauthenticate(XCmdPtr paramPtr,short refNum,Str255);
OSErr Xkrbtgt(XCmdPtr paramPtr,short refNum,Str255);
OSErr Xauthmanversion(XCmdPtr paramPtr,short refNum,Str255);
OSErr Xlocalrealm(XCmdPtr paramPtr,short refNum,Str255);
OSErr Xexpire(XCmdPtr paramPtr,short refNum,Str255);
typedef struct {
char *name;
OSErr (*proc)(XCmdPtr,short,Str255);
} _operations;
OSErr
Xcmdversion(XCmdPtr paramPtr,short refNum,Str255 theString)
{
NumToString((long)XCMD_VERSION,theString);
return(noErr);
}
OSErr
Xauthenticate(XCmdPtr paramPtr,short refNum,Str255 theString)
{
OSErr err;
short ticketLen,version;
char ticket[MAX_KTXT_LEN];
if (!(err=expireV4Ticket(refNum,(void *)"\pkrbtgt",NULL,NULL))) {
err=getV4Ticket(refNum,(void *)&ticket,&ticketLen,(void *)"\pkrbtgt", \
NULL,NULL,INFINITE_LIFETIME,PROMPT_FLAG);
if (!err || err==paramErr) {
err=Xkrbtgt(paramPtr,refNum,theString);
}
}
return(err);
}
OSErr
Xkrbtgt(XCmdPtr paramPtr,short refNum,Str255 theString)
{
OSErr err;
short ticketNum;
_V4ticketInfo theInfo;
ticketNum=0;
while (!(err=getV4TicketNinfo(refNum,ticketNum++,&theInfo))) {
if (!IUEqualString(theInfo.sName,"\pkrbtgt")) {
BlockMove(&theInfo.pName[1],
&theString[theString[0]+1],
(unsigned)theInfo.pName[0]);
theString[0]+=(unsigned)theInfo.pName[0];
if (theInfo.pInstance[0]) {
theString[++theString[0]]='.';
BlockMove(&theInfo.pInstance[1],
&theString[theString[0]+1],
((unsigned)theInfo.pInstance[0])+1L);
theString[0]+=(unsigned)theInfo.pInstance[0];
}
if (theInfo.pRealm[0]) {
theString[++theString[0]]='@';
BlockMove(&theInfo.pRealm[1],
&theString[theString[0]+1],
((unsigned)theInfo.pRealm[0])+1L);
theString[0]+=(unsigned)theInfo.pRealm[0];
}
break;
}
}
if (err==paramErr) err=noErr;
return(err);
}
OSErr
Xauthmanversion(XCmdPtr paramPtr,short refNum,Str255 theString)
{
OSErr err;
short version;
if (!(err=openAuthMan(&refNum,&version))) {
NumToString((long)version,theString);
}
return(err);
}
OSErr
Xlocalrealm(XCmdPtr paramPtr,short refNum,Str255 theString)
{
short realmType;
return(getDefaultRealm(refNum,(void *)theString,&realmType));
}
OSErr
Xexpire(XCmdPtr paramPtr,short refNum,Str255 theString)
{
return(expireV4Ticket(refNum,NULL,NULL,NULL));
}
short
strlenandzero(char *p)
{
short theLen=1; // length includes terminating zero
while (*p++) ++theLen;
return(theLen);
}
pascal
main(XCmdPtr paramPtr)
{
Handle param1;
OSErr err;
Str255 theString;
short len,loop,refNum,version=0;
_operations operations[10];
operations[0].name="xcmdversion"; operations[0].proc=Xcmdversion;
operations[1].name="authenticate"; operations[1].proc=Xauthenticate;
operations[2].name="krbtgt"; operations[2].proc=Xkrbtgt;
operations[3].name="authmanversion"; operations[3].proc=Xauthmanversion;
operations[4].name="localrealm"; operations[4].proc=Xlocalrealm;
operations[5].name="expire"; operations[5].proc=Xexpire;
operations[6].name=NULL; operations[6].proc=NULL;
if (!(err=openAuthMan(&refNum,&version))) {
if (version < AUTHMAN_VERSION_CODE || paramPtr->paramCount<1) {
err=-1;
}
else {
param1=(paramPtr->params)[0];
HLock(param1);
theString[0]=0;
for (loop=0; operations[loop].name; loop++) {
len=strlenandzero(operations[loop].name);
if (!IUMagIDString(*param1,operations[loop].name,(long)len,(long)len)) {
theString[0]=0;
if (!(err=(*(operations[loop].proc))(paramPtr,refNum,theString))) {
paramPtr->returnValue=PasToZero(paramPtr,theString);
}
break;
}
}
HUnlock(param1);
}
}
if (err) NumToString((long)err,theString);
if (theString[0]) paramPtr->returnValue=PasToZero(paramPtr,theString);
}